import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/21 9:07
 * @description 泛型设计，使得返回的可以为任意类型
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    class PeekingIterator<E> implements Iterator<E> {
        private Iterator<E> iterator;
        private E nextElement;

        public PeekingIterator(Iterator<E> iterator) {
            this.iterator = iterator;
            nextElement = iterator.next();
        }

        public E peek() {
            return nextElement;
        }

        @Override
        public E next() {
            E ret = nextElement;
            nextElement = iterator.hasNext() ? iterator.next() : null;
            return ret;
        }

        @Override
        public boolean hasNext() {
            return nextElement != null;
        }
    }
}
